﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataExtractionLanguage
{
    /// <summary>
    /// Represents a term of any expression.
    /// </summary>
    /// <remarks>
    /// Term class is used in many different situaltion in the language. It is used with the Function when we want to pass parameter as an Expression, It is formulate the terms of the Expression.
    /// In the other hand Term class is used with the Join linkage part after On keyword to specifiy how the to table is linked to each other.
    /// DailyNews.Source
    /// </remarks>
    [Serializable]
    public class Term
    {
        /// <summary>
        /// Gets or sets the source alias which in reality is SourceStatement.
        /// </summary>
        public string SourceAlias { get; set; }

        /// <summary>
        /// Gets or sets the column alias.
        /// </summary>
        public string ColumnAlias { get; set; }

        /// <summary>
        /// Gets or sets the property of the term.
        /// </summary>
        public PropertyMember Property { get; set; }

        public void AddIdentifier(string identifier)
        {
            if (!string.IsNullOrEmpty(ColumnAlias))
                SourceAlias = ColumnAlias;

            ColumnAlias = identifier;
        }

        public override string ToString()
        {
            if (SourceAlias == null)
                return string.Format("{0}.{1}", ColumnAlias, Property);
            else
                return string.Format("{0}.{1}.{2}", SourceAlias, ColumnAlias, Property);
        }
    }
}